﻿#ifndef PID_H
#define PID_H

#include <QDebug>

class Pid {
public:
    Pid();
    Pid(double kp, double ki, double kd, double IntegralSaturation = 999999999, double adjustLimit = 9999999999);

    double positionPid(double err);
    double incrementPid(double err);
    void clearErr();

    double kp() const;
    void setKp(double kp);

    double ki() const;
    void setKi(double ki);

    double kd() const;
    void setKd(double kd);

    double integralSaturation() const;
    void setIntegralSaturation(double integralSaturation);

    double adjustLimit() const;
    void setAdjustLimit(double adjustLimit);

private:
    double kp_;
    double ki_;
    double kd_;
    double integral_err_;
    double dif_err_;
    double pre_err_;
    double last_err_;
    double integral_saturation_; //积分饱和,用于限制ki的作用
    double adjust_limit_;
};

#endif // PID_H
